import 'package:json_annotation/json_annotation.dart';

part 'bill_detail_model.g.dart';

/// 账单详情响应模型
@JsonSerializable()
class BillDetailResponse {
  final int code;
  final String message;
  final BillDetailData? data;

  const BillDetailResponse({
    required this.code,
    required this.message,
    this.data,
  });

  factory BillDetailResponse.fromJson(Map<String, dynamic> json) =>
      _$BillDetailResponseFromJson(json);

  Map<String, dynamic> toJson() => _$BillDetailResponseToJson(this);
}

/// 账单详情数据模型
@JsonSerializable()
class BillDetailData {
  final double allExpendSum;
  final double allIncomeSum;
  final List<BillDayData> billData;

  const BillDetailData({
    required this.allExpendSum,
    required this.allIncomeSum,
    required this.billData,
  });

  factory BillDetailData.fromJson(Map<String, dynamic> json) =>
      _$BillDetailDataFromJson(json);

  Map<String, dynamic> toJson() => _$BillDetailDataToJson(this);
}

/// 每日账单数据模型
@JsonSerializable()
class BillDayData {
  final BillItemData itemData;
  final List<BillItem> itemList;

  const BillDayData({
    required this.itemData,
    required this.itemList,
  });

  factory BillDayData.fromJson(Map<String, dynamic> json) =>
      _$BillDayDataFromJson(json);

  Map<String, dynamic> toJson() => _$BillDayDataToJson(this);
}

/// 每日汇总数据模型
@JsonSerializable()
class BillItemData {
  final String date;
  final double expendSum;
  final double incomeSum;

  const BillItemData({
    required this.date,
    required this.expendSum,
    required this.incomeSum,
  });

  factory BillItemData.fromJson(Map<String, dynamic> json) =>
      _$BillItemDataFromJson(json);

  Map<String, dynamic> toJson() => _$BillItemDataToJson(this);
}

/// 账单条目模型
@JsonSerializable()
class BillItem {
  final int id;
  final String? name;
  final double money;
  final String? address;
  final int? accountId;
  final int? merchantId;
  final int userId;
  final int classifyId;
  final int secondClassifyId;
  final String? remark;
  final String? img;
  final String createTime;
  final String? updateTime;
  final int? accountBookId;
  final String? icon;
  final String? bankName;
  final String? merchantName;
  final int type; // 0: 支出, 1: 收入

  const BillItem({
    required this.id,
    this.name,
    required this.money,
    this.address,
    this.accountId,
    this.merchantId,
    required this.userId,
    required this.classifyId,
    required this.secondClassifyId,
    this.remark,
    this.img,
    required this.createTime,
    this.updateTime,
    this.accountBookId,
    this.icon,
    this.bankName,
    this.merchantName,
    required this.type,
  });

  factory BillItem.fromJson(Map<String, dynamic> json) =>
      _$BillItemFromJson(json);

  Map<String, dynamic> toJson() => _$BillItemToJson(this);
}